﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebAssets
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtomSub_Click(object sender, EventArgs e)
        {
           var isAllNotNull =  ServerVerify();
            if (!isAllNotNull)
                return;
            FixedAssetInfoes model = new FixedAssetInfoes
            {
                Id = Guid.NewGuid(),
                Brand = textBoxBrand.Text.Trim(),
                Model = textBoxModel.Text.Trim(),
                AssetType = textBoxAssetType.Text.Trim(),
                UsingName = textBoxUsingName.Text.Trim(),
                UsingNameDepartment = textBoxUsingNameDepartment.Text.Trim(),
                SerialNumber = textBoxSerialNumber.Text.Trim(),
                ServiceNumber = textBoxServiceNumber.Text.Trim()
            };
            using (EFDatabaseEntities db = new EFDatabaseEntities())//数据插入保存
            {
                db.FixedAssetInfoes.Add(model);
                db.SaveChanges();
            }
            Response.Write("<script>alert('保存成功！');</script>");
            ClerarText();
        }
        /// <summary>
        /// 验证是否有空值
        /// </summary>
        /// <returns></returns>
        private bool ServerVerify()
        {
            if (textBoxBrand.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入品牌');</script>");
                return false;
            }
            if (textBoxModel.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入型号');</script>");
                return false;
            }
            if (textBoxAssetType.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入类型');</script>");
                return false;
            }
            if (textBoxUsingName.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入使用者');</script>");
                return false;
            }
            if (textBoxUsingNameDepartment.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入使用者部门');</script>");
                return false;
            }
            if (textBoxSerialNumber.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入系列号');</script>");
                return false;
            }
            return true;
        }
        /// <summary>
        /// 清空输入框中数据
        /// </summary>
        private void ClerarText()
        {
            textBoxBrand.Text = "";
            textBoxModel.Text = "";
            textBoxAssetType.Text = "";
            textBoxUsingName.Text = "";
            textBoxUsingNameDepartment.Text = "";
            textBoxSerialNumber.Text = "";
            textBoxServiceNumber.Text = "";
        }
    }
}